## Computation of products by means of an index table

from PyM import *


def index_table(x): return [(0*x,'_')] + [(x**j,j) for j in range(order(x))]

def inverse(T): return [(b,a) for (a,b) in T]

# Example: index table L and exponential table E of K

[K,x] = extension(Zn(3),[1,0,-1,1],'x')  # x is primitive

q = cardinal(K)

L = index_table(x)
def L_(z): return lookup(z,L)

E = inverse(L)
def E_(z): return lookup(z,E)

# Computation of products

def p(a,b): return E_((L_(a)+L_(b)) % (q-1))

a = x**6; b = x**15

show(L_(a),L_(b))

show(a*b)

show(p(a,b))